package org.dromara.pay.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.pay.domain.vo.PayAlipayOrdersSignVo;
import org.dromara.pay.domain.query.PayAlipayOrdersSignQuery;
import org.dromara.pay.domain.bo.PayAlipayOrdersSignBo;
import org.dromara.pay.crud.service.IPayAlipayOrdersSignCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * pay-支付宝订单信息
 *
 * @author yf
 * @date 2024-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/alipayOrdersSign")
public class PayAlipayOrdersSignCrudController extends BaseController {

    private final IPayAlipayOrdersSignCrudService payAlipayOrdersSignService;

    /**
     * 分页查询支付宝订单信息列表
     */
    @SaCheckPermission("pay:alipayOrdersSign:list")
    @GetMapping("/list")
    public TableDataInfo<PayAlipayOrdersSignVo> list(PayAlipayOrdersSignQuery query, PageQuery pageQuery) {
         return payAlipayOrdersSignService.queryPageList(query, pageQuery);
    }

    /**
     * 查询支付宝订单信息列表
     */
    @SaCheckPermission("pay:alipayOrdersSign:list")
    @GetMapping("/allList")
    public TableDataInfo<PayAlipayOrdersSignVo> allList(PayAlipayOrdersSignQuery query) {
        List<PayAlipayOrdersSignVo> list =  payAlipayOrdersSignService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出支付宝订单信息列表
     */
    @SaCheckPermission("pay:alipayOrdersSign:export")
    @Log(title = "支付宝订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayAlipayOrdersSignQuery query, HttpServletResponse response) {
        List<PayAlipayOrdersSignVo> list = payAlipayOrdersSignService.queryList(query);
        ExcelUtil.exportExcel(list, "支付宝订单信息", PayAlipayOrdersSignVo.class, response);
    }

    /**
     * 获取支付宝订单信息详细信息
     *
     * @param alipayId 主键
     */
    @SaCheckPermission("pay:alipayOrdersSign:query")
    @GetMapping("/{alipayId}")
    public R<PayAlipayOrdersSignVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String alipayId) {
        return R.ok(payAlipayOrdersSignService.queryById(alipayId));
    }

    /**
     * 新增支付宝订单信息
     */
    @SaCheckPermission("pay:alipayOrdersSign:add")
    @Log(title = "支付宝订单信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayAlipayOrdersSignBo bo) {
        return toAjax(payAlipayOrdersSignService.insertByBo(bo));
    }

    /**
     * 修改支付宝订单信息
     */
    @SaCheckPermission("pay:alipayOrdersSign:edit")
    @Log(title = "支付宝订单信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayAlipayOrdersSignBo bo) {
        return toAjax(payAlipayOrdersSignService.updateByBo(bo));
    }

    /**
     * 删除支付宝订单信息
     *
     * @param alipayIds 主键串
     */
    @SaCheckPermission("pay:alipayOrdersSign:remove")
    @Log(title = "支付宝订单信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{alipayIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] alipayIds) {
        return toAjax(payAlipayOrdersSignService.deleteWithValidByIds(List.of(alipayIds), true));
    }
}
